<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\BuildingExamine;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class BuildingExamineController extends AdminController
{
    /**
     * Author:Zhongyuan Lu
     * 审核管理 列表展示
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new BuildingExamine(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('uid');
            $grid->column('building_id');   //房源id
            $grid->column('name');          //小区名称
            $grid->column('title');         //标题
            $grid->column('area');          //面积（单位：㎡）
            $grid->column('total_price');   //总价（单位：元）
            $grid->column('province');      //省
            $grid->column('city');          //市
            $grid->column('region');        //区
            //状态（0:待审核 1：审核成功 -1 未通过审核）
            $grid->column('status')->display(function ($status) {
                $options = config('setting.examine_status');
                return $options[$status];
            });
            $grid->column('sort');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new BuildingExamine(), function (Show $show) {
            $show->field('id');
            $show->field('uid');
            $show->field('building_id');
            $show->field('name');
            $show->field('title');
            $show->field('area');
            $show->field('total_price');
            $show->field('province');
            $show->field('city');
            $show->field('region');
            $show->field('status');
            $show->field('sort');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new BuildingExamine(), function (Form $form) {
            $form->display('id');
            $form->text('uid');
            $form->text('building_id');
            $form->text('name');
            $form->text('title');
            $form->text('area');
            $form->text('total_price');
            $form->text('province');
            $form->text('city');
            $form->text('region');
            $form->text('status');
            $form->text('sort');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
